package com.base.cn.platform.os.controller.manage.join;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.entity.manage.join.SysRoleFunction;
import com.base.cn.platform.os.service.manage.join.SysRoleFunctionBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 角色和资源权限关联的Controller
 *
 * @author s.li
 * @create 2018-03-06 15:19
 */
@RestController
@RequestMapping("/manage")
public class SysRoleFunctionController extends BaseController {

    @Autowired
    private SysRoleFunctionBiz sysRoleFunctionBiz;

    /**
     * 获取角色与权限的关联的数据列表
     * @param roleId 角色ID
     * @return List<SysRoleFunction>
     */
    @RequestMapping("/findRoleFunctionList")
    public List<SysRoleFunction> findRoleFunctionList(@RequestParam("roleId")BigDecimal roleId){
        return sysRoleFunctionBiz.find(" roleId = "+roleId,null,null);
    }

    /**
     * 保存角色授权数据
     * @param roleId 角色ID
     * @param functionIds 权限ID组
     * @return Map<String,Object>
     */
    @RequestMapping("/saveRoleFunctionSubject")
    public Map<String,Object> saveRoleFunctionSubject(@RequestParam("roleId") BigDecimal roleId,
                                                      @RequestParam(value = "functionIds",required = false) String functionIds){

        sysRoleFunctionBiz.saveSysRoleFunctionSubject(roleId,functionIds);
        return ResultUtil.SUCCESS("角色授权数据保存成功");
    }
}
